from pathlib import Path
from PIL import Image

image_dir = Path(r"F:\图")

total_files_checked = 0
files_with_errors = 0

for image_path in image_dir.glob("**/*.*"):
    if image_path.suffix in [".png", ".jpg", ".jpeg", ".bmp", ".gif"]:
        total_files_checked += 1
        try:
            print(total_files_checked, image_path.name)
            with Image.open(image_path) as img:
                img.load()
        except (FileNotFoundError, OSError, IOError) as e:
            files_with_errors += 1
            print(f"文件 {image_path} 可能已损坏: {e}")

print(f"\n总计检查了 {total_files_checked} 个文件，其中 {files_with_errors} 个文件可能已损坏。")
